package com.hbsx.why.ui.mine;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hbsx.why.R;
import com.hbsx.why.base.BaseActivity;
import com.hbsx.why.utils.AppUtilsDemo;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by User on 2017/4/28.
 */

public class SetActivity extends BaseActivity implements CompoundButton.OnCheckedChangeListener {

    @BindView(R.id.tv_topTitle)
    TextView tvTopTitle;
    @BindView(R.id.settingUI_middleItem_check02)
    CheckBox pushCheck;
    @BindView(R.id.settingUI_middleItem_check03)
    CheckBox soundChenck;
    @BindView(R.id.settingUI_middleItem_check04)
    CheckBox updateCheck;
    @BindView(R.id.settingUI_middleItem_hc)
    TextView settingUIMiddleItemHc;
    @BindView(R.id.mine_aboutus_click)
    RelativeLayout mineAboutusClick;
    private Context context = this;
    private SharedPreferences sharedPreferences;

    @Override
    protected int getLayoutResId() {
        return R.layout.ui_mine_set;
    }

    @Override
    protected void initView() {

    }

    protected void onInit() {
        tvTopTitle.setText("设置");
        sharedPreferences = context.getSharedPreferences(AppUtilsDemo.user_share, MODE_PRIVATE);
        pushCheck.setOnCheckedChangeListener(this);
        soundChenck.setOnCheckedChangeListener(this);
        updateCheck.setOnCheckedChangeListener(this);
        pushCheck.setChecked(sharedPreferences.getBoolean(AppUtilsDemo.nm_pushCheck, true));
        soundChenck.setChecked(sharedPreferences.getBoolean(AppUtilsDemo.nm_soundCheck, true));
        updateCheck.setChecked(sharedPreferences.getBoolean(AppUtilsDemo.nm_updateCheck, true));
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
            case R.id.settingUI_middleItem_check02:
                commitEditor(0, isChecked);
                break;
            case R.id.settingUI_middleItem_check03:
                commitEditor(1, isChecked);
                break;
            case R.id.settingUI_middleItem_check04:
                commitEditor(2, isChecked);
                break;
        }
    }

    private void commitEditor(int type, boolean isChecked) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        switch (type) {
            case 0:
                editor.putBoolean(AppUtilsDemo.nm_pushCheck, isChecked);
                break;
            case 1:
                editor.putBoolean(AppUtilsDemo.nm_soundCheck, isChecked);
                break;
            case 2:
                editor.putBoolean(AppUtilsDemo.nm_updateCheck, isChecked);
                break;
        }
        editor.commit();
    }

    @OnClick({R.id.settingUI_middleItem_layout03, R.id.mine_aboutus_click})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.settingUI_middleItem_layout03:
                settingUIMiddleItemHc.setText("0M");
//        if (UtilPermission.judgePermisson(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
//            final ConfirmDialog confirmDialog = new ConfirmDialog(context, R.mipmap.ic_warn, "确定清除缓存？", "确定", "取消", 1);
//            confirmDialog.show();
//            confirmDialog.setClicklistener(new ConfirmDialog.ClickListenerInterface() {
//                @Override
//                public void doConfirm() {
//                    confirmDialog.dismiss();
//                    DataCleanManager.cleanApplicationData(context, "" + ImageLoader.getInstance().getDiskCache().getDirectory());
//                    cacheTxt.setText("0MB");
////					ImageLoader.getInstance().clearMemoryCache();
////					ImageLoader.getInstance().clearDiskCache();
//                }
//
//                @Override
//                public void doCancel() {
//                    confirmDialog.dismiss();
//                }
//            });
//
//        }
                break;
            //关于我们
            case R.id.mine_aboutus_click:
                launch(AboutUsActivity.class);
                break;

        }

    }
}
